﻿#include "GameCore.h"

GameCore::_GameStatus GameCore::Sha(int player, int player1, bool bAllowShan, _GameChuPaiType type)
{
    _GameButtonValue ret;
    int Weapon = _Pai::Value_Null;  //装备/使用的武器

    if(type == Game_ChuPai_Type_ZhuDong && m_arrayPlayer[player].m_nSha > 0)      //是否减杀
    {
        if(m_arrayPlayer[player].containZhuangBei(_Pai::Value_LianNu))
            ;
        else if(m_arrayPlayer[player].containJiNeng(_JiNeng::JiNengValue_MengGuDiGuo))
            ;
        else
            m_arrayPlayer[player].m_nSha--;
    }


    //检查使用的武器
    //直接使用
    if(m_arrayStep[0].nSelectType[0] == _BaseObject::Area_ZhuangBei)
    {
        switch(m_arrayPlayer[player].getZhuangBeiData(_BaseObject::Area_WuQi)->value())
        {
        case _Pai::Value_ZhangBa:
        case _Pai::Value_TanSu:
            Weapon = m_arrayPlayer[player].getZhuangBeiData(_BaseObject::Area_WuQi)->value();
            break;
        default:
            emit s_Critical(_T("[!GameCore]Weapon ERROR!"));
            break;
        }
    }
    //有被动装备
    else if(m_arrayPlayer[player].getZhuangBeiData(_BaseObject::Area_WuQi) != nullptr)
    {
        switch(m_arrayPlayer[player].getZhuangBeiData(_BaseObject::Area_WuQi)->value())
        {
        case _Pai::Value_LianNu:
        case _Pai::Value_QingLong:
        case _Pai::Value_GuanShiFu:
        case _Pai::Value_HanBing:
            Weapon = m_arrayPlayer[player].getZhuangBeiData(_BaseObject::Area_WuQi)->value();
            break;
        default:
            //qDebug()<<"Weapon Err2:"<<m_arrayPlayer[player].getZhuangBeiData(_Pai::Type_WuQi)->value();
            break;
        }
    }


//被杀者决算:

    m_strMsg = _T("%1对%2使用%3")
        .arg(getPlayerShowName(player))
        .arg(getPlayerShowName(player1))
        .arg(_Pai::getName(_Pai::Value_Sha));
        //.arg(_Pai::getName(_Pai::Value_Shan));
    emit s_Message(m_strMsg);
    ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);



    int shanCount = 1;  //需要的闪个数
    if(m_arrayPlayer[player].containJiNeng(_JiNeng::JiNengValue_AYuWang))
        shanCount = 2;

    if(bAllowShan)
        ret = ChuShan(player1, shanCount, m_strMsg);
    else
        ret = Game_Button_Cancel;

    if(ret == Game_Button_Cancel)
    {
        if(Weapon == _Pai::Value_TanSu)
        {
            if(DiaoXue(2,player1,player,_Pai::Value_Sha) != Game_Status_Continue)return gameStatus();

            m_strMsg = m_hashGameMessage[_Pai::Value_TanSu][1]
                .arg(getPlayerShowName(player))
                .arg(_Pai::getName(_Pai::Value_TanSu));
            emit s_Message(m_strMsg);
            ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

            return gameStatus();
        }
        else if(Weapon == _Pai::Value_HanBing)
        {
            switch(ret = ChuPai(player,GameCore::Game_ChuPai_Type_Pai,_Pai::Value_HanBing,-1,-1,player1))
            {
            case Game_Button_Cancel:    //寒冰取消
                return DiaoXue(1,player1,player,_Pai::Value_Sha);
            case Game_Button_OK:        //寒冰确定
                int i;
                for(i = 0; i < m_arrayStep[0].nSelectCount; i++)
                {
                    switch (m_arrayStep[0].nSelectType[i]) {
                    case _BaseObject::Area_ShouPai:
                        QiPai(m_arrayPlayer[player1].qiShouPai(m_arrayStep[0].nSelectValue[i],false));
                        break;
                    case _BaseObject::Area_PanDing:
                        QiPai(m_arrayPlayer[player1].qiPanDing(m_arrayStep[0].nSelectValue[i]));
                        break;
                    default:
                        if(m_arrayStep[0].nSelectType[i] & _BaseObject::Area_ZhuangBei)
                            QiPai(m_arrayPlayer[player1].qiZhuangBei(m_arrayStep[0].nSelectType[i]));
                        else
                        {
                            emit s_Critical(_T("[!GameCore]寒冰选牌 ERROR:%1!").arg(m_arrayStep[0].nSelectType[i]));
                            return setGameStatus(Game_Status_ERROR);
                        }
                        break;
                    }
                }
                m_arrayPlayer[player1].tiaoZhengShouPaiDui();
                emit s_RefreshAllPokePosition();

                m_strMsg = m_hashGameMessage[_Pai::Value_HanBing][1]
                        .arg(getPlayerShowName(player))
                        .arg(_Pai::getName(_Pai::Value_HanBing));
                emit s_Message(m_strMsg);
                ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

                return gameStatus();
                break;
            default:
                emit s_Critical(_T("[!GameCore]寒冰 ERROR:%1!").arg(ret));
                return setGameStatus(Game_Status_ERROR);
            }
        }
        else
            return DiaoXue(1,player1,player,_Pai::Value_Sha);
    }
    else if(ret == Game_Button_OK)
    {
        ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

        ChuShanJiNeng(player, player1);
        if(gameStatus() != Game_Status_Continue)return gameStatus();


        if(Weapon == _Pai::Value_QingLong)
        {
            m_strMsg = _T("%1效果触发")
                .arg(_Pai::getName(_Pai::Value_QingLong));
                //.arg(_Pai::getName(_Pai::Value_Shan));
            //emit s_Message(m_strMsg);
            //ShowChuPaiMessage(m_strMsg, 0);

            ret = ChuSha(player, 1, 1, -1, m_strMsg);
            if(ret == Game_Button_Cancel)
                ;
            else if(ret == Game_Button_OK)
            {
                //ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

                Sha(player,player1,true,Game_ChuPai_Type_Pai);
                if(gameStatus() != Game_Status_Continue)return gameStatus();
                /*
                m_strMsg = m_hashGameMessage[_Pai::Value_Sha][2]
                    .arg(getPlayerShowName(player))
                    .arg(getPlayerShowName(player1))
                    .arg(_Pai::getName(_Pai::Value_Sha));
                    //.arg(_Pai::getName(_Pai::Value_Shan));
                emit s_Message(m_strMsg);

                m_strMsg = _T("%1对%2使用%3")
                    .arg(getPlayerShowName(player))
                    .arg(getPlayerShowName(player1))
                    .arg(_Pai::getName(_Pai::Value_Sha));
                    //.arg(_Pai::getName(_Pai::Value_Shan));
                emit s_Message(m_strMsg);
                ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

                ret = ChuShan(player1, shanCount, m_strMsg);
                if(ret == Game_Button_Cancel)
                {
                    DiaoXue(1,player1,player,_Pai::Value_Sha);
                    break;
                }
                else if(ret == Game_Button_OK)
                {
                    ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);
                    continue;
                }
                else
                    return setGameStatus(Game_Status_ERROR);
                    */
            }
            else
                return setGameStatus(Game_Status_ERROR);
        }
        else if(Weapon == _Pai::Value_GuanShiFu)
        {
            switch(ret = ChuPai(player,GameCore::Game_ChuPai_Type_Pai,_Pai::Value_GuanShiFu))
            {
            case Game_Button_Cancel:
                break;
            case Game_Button_OK:
                QiPai(m_arrayPlayer[player].qiShouPai(m_arrayStep[0].nSelectValue[0],false));
                QiPai(m_arrayPlayer[player].qiShouPai(m_arrayStep[0].nSelectValue[1],false));
                m_arrayPlayer[player].tiaoZhengShouPaiDui();
                emit s_RefreshAllPokePosition();

                if(DiaoXue(1,player1,player,_Pai::Value_Sha) != Game_Status_Continue)return gameStatus();

                m_strMsg = m_hashGameMessage[_Pai::Value_GuanShiFu][1]
                        .arg(getPlayerShowName(player))
                        .arg(_Pai::getName(_Pai::Value_GuanShiFu));
                emit s_Message(m_strMsg);
                ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

                break;

            default:
                emit s_Critical(_T("[!GameCore]贯石斧 ERROR:%1!").arg(ret));
                return setGameStatus(Game_Status_ERROR);
            }
        }
        return gameStatus();
    }
    return setGameStatus(Game_Status_ERROR);
}

int GameCore::ChiTao(int player)
{
    m_arrayPlayer[player].addBlood(1);

    if(m_arrayPlayer[player].m_nTiLi > m_arrayPlayer[player].m_nTiLiShangXian)
    {
        emit s_Critical(_T("[!GameCore]你被撑死了 ERROR!"));
        //setGameStatus(Game_Status_ERROR);
    }

    m_strMsg = m_hashGameMessage[_Pai::Value_Tao][1]
        .arg(getPlayerShowName(player))
        .arg(_Pai::getName(_Pai::Value_Tao));
    emit s_Message(m_strMsg);
    //ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

    return m_arrayPlayer[player].m_nTiLi;
}

GameCore::_GameStatus GameCore::Chai(int player, int player1)
{
    _Pai *p = nullptr;

    m_strMsg = m_hashGameMessage[_Pai::Value_Chai][2]
        .arg(getPlayerShowName(player))
        .arg(getPlayerShowName(player1))
        .arg(_Pai::getName(_Pai::Value_Chai));
    emit s_Message(m_strMsg);
    ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);


    if(WenTi(player, m_strMsg, 0) == false)
    {
        //m_strMsg = m_hashGameMessage[_Pai::Value_All][6]
        //    .arg(getPlayerShowName(player));
        //emit s_Message(m_strMsg);
        //ShowChuPaiMessage(m_strMsg);
        return gameStatus();
    }
    if(gameStatus() != Game_Status_Continue)return gameStatus();

    //m_strMsg = m_hashGameMessage[_Pai::Value_All][7]
    //    .arg(getPlayerShowName(player));
    //emit s_Message(m_strMsg);
    //ShowChuPaiMessage(m_strMsg);



    switch(m_arrayStep[2].nSelectType[0])
    {
    case _BaseObject::Area_ShouPai:
        p = m_arrayPlayer[player1].qiShouPai(m_arrayStep[2].nSelectValue[0],true);
        break;
    case _BaseObject::Area_ZhuangBei:
        p = m_arrayPlayer[player1].qiZhuangBei((_BaseObject::_Area)(m_arrayStep[2].nSelectValue[0]));
        break;
    case _BaseObject::Area_PanDing:
        p = m_arrayPlayer[player1].qiPanDing(m_arrayStep[2].nSelectValue[0]);
        break;
    default:
        emit s_Critical(_T("[!GameCore]Chai ERROR!"));
        break;
    }

    QiPai(p);
    emit s_RefreshAllPokePosition();

    m_strMsg = m_hashGameMessage[_Pai::Value_Chai][3]
        .arg(getPlayerShowName(player))
        .arg(getPlayerShowName(player1))
        .arg(p->getName());
    emit s_Message(m_strMsg);
    ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

    return gameStatus();
}

GameCore::_GameStatus GameCore::Shun(int player, int player1)
{
    _Pai *p = nullptr;

    m_strMsg = m_hashGameMessage[_Pai::Value_Shun][2]
        .arg(getPlayerShowName(player))
        .arg(getPlayerShowName(player1))
        .arg(_Pai::getName(_Pai::Value_Shun));
    emit s_Message(m_strMsg);
    ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

    if(WenTi(player, m_strMsg, 0) == false)
    {
        //m_strMsg = m_hashGameMessage[_Pai::Value_All][6]
        //    .arg(getPlayerShowName(player));
        //emit s_Message(m_strMsg);
        //ShowChuPaiMessage(m_strMsg);
        return gameStatus();
    }
    if(gameStatus() != Game_Status_Continue)return gameStatus();

    //str = m_hashGameMessage[_Pai::Value_All][7]
    //    .arg(getPlayerShowName(player));
    //emit s_Message(str);
    //ShowChuPaiMessage(str);



    switch(m_arrayStep[2].nSelectType[0])
    {
    case _BaseObject::Area_ShouPai:
        p = m_arrayPlayer[player1].qiShouPai(m_arrayStep[2].nSelectValue[0],true);
        break;
    case _BaseObject::Area_ZhuangBei:
        p = m_arrayPlayer[player1].qiZhuangBei((_BaseObject::_Area)(m_arrayStep[2].nSelectValue[0]));
        break;
    case _BaseObject::Area_PanDing:
        p = m_arrayPlayer[player1].qiPanDing(m_arrayStep[2].nSelectValue[0]);
        break;
    default:
        emit s_Critical(_T("[!GameCore]Shun ERROR!"));
        break;
    }

    if(m_arrayPlayer[player].getShouPai(p) < 0)
    {
        QiPai(p);
        emit s_RefreshAllPokePosition();
    }
    else
    {
        emit s_RefreshAllPokePosition();

        m_strMsg = m_hashGameMessage[_Pai::Value_Shun][3]
            .arg(getPlayerShowName(player))
            .arg(getPlayerShowName(player1))
            .arg(p->getName());
        emit s_Message(m_strMsg);
        ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);
    }

    return gameStatus();
}

GameCore::_GameStatus GameCore::WuZhong(int player)
{
    m_strMsg = m_hashGameMessage[_Pai::Value_WuZhong][0]
        .arg(getPlayerShowName(player))
        .arg(_Pai::getName(_Pai::Value_WuZhong));
    emit s_Message(m_strMsg);
    ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

    if(WenTi(player, m_strMsg, 0) == false)
    {
        //m_strMsg = m_hashGameMessage[_Pai::Value_All][6]
        //    .arg(getPlayerShowName(player));
        //emit s_Message(m_strMsg);
        //ShowChuPaiMessage(m_strMsg);
        return gameStatus();
    }
    if(gameStatus() != Game_Status_Continue)return gameStatus();
    //m_strMsg = m_hashGameMessage[_Pai::Value_All][7]
    //    .arg(getPlayerShowName(player));
    //emit s_Message(m_strMsg);
    //ShowChuPaiMessage(m_strMsg);


    if(!MoPai(player,2))
    {
        emit s_Critical(_T("[!GameCore]WuZhong ERROR!"));
        return setGameStatus(Game_Status_ERROR);
    }

    emit s_RefreshAllPokePosition();

    m_strMsg = m_hashGameMessage[_Pai::Value_All][2]
            .arg(getPlayerShowName(player))
            .arg(2);
    ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

    return gameStatus();
}

GameCore::_GameStatus GameCore::JieDao(int player, int player1, int player2)
{
    m_strMsg = m_hashGameMessage[_Pai::Value_JieDao][2]
        .arg(getPlayerShowName(player))
        .arg(getPlayerShowName(player1))
        .arg(_Pai::getName(_Pai::Value_JieDao))
        .arg(getPlayerShowName(player2));
    emit s_Message(m_strMsg);
    ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

    if(WenTi(player, m_strMsg, 0) == false)
    {
        //m_strMsg = _T("%1回答错误!锦囊牌失效!")
        //    .arg(getPlayerShowName(player));
        //emit s_Message(m_strMsg);
        //ShowChuPaiMessage(m_strMsg);
        return gameStatus();
    }
    if(gameStatus() != Game_Status_Continue)return gameStatus();
    //m_strMsg = _T("%1回答正确!")
    //    .arg(getPlayerShowName(player));
    //emit s_Message(m_strMsg);
    //ShowChuPaiMessage(m_strMsg);


    m_strMsg = m_hashGameMessage[_Pai::Value_JieDao][3]
        .arg(getPlayerShowName(player))
        .arg(getPlayerShowName(player1))
        .arg(getPlayerShowName(player2));
    emit s_Message(m_strMsg);
    ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

    //qDebug()<<"我的ID："<<iMyID;

    _GameButtonValue ret;
    //ret = ChuPai(player1,GameCore::Game_ChuPai_Type_Pai,_Pai::Value_Sha);
    ret = ChuSha(player1, 1, 1, -1, m_strMsg);

    //qDebug()<<"出牌返回值"<<ret;
    if(ret == Game_Button_Cancel)
    {
        _Pai *p = m_arrayPlayer[player1].qiZhuangBei(_BaseObject::Area_WuQi);
        if(m_arrayPlayer[player].getShouPai(p) < 0)
        {
            QiPai(p);
            emit s_RefreshAllPokePosition();
        }
        else
        {
            emit s_RefreshAllPokePosition();

            //qDebug()<<"没出杀"<<ret;
            m_strMsg = _T("%1得到%2的%3")
                    .arg(getPlayerShowName(player))
                    .arg(getPlayerShowName(player1))
                    .arg(p->getName());
            emit s_Message(m_strMsg);
            ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);
        }

        return gameStatus();
    }
    else if(ret == Game_Button_OK)
    {
        //ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

        return Sha(player1,player2,true,Game_ChuPai_Type_Pai);
    }
    else
        return setGameStatus(Game_Status_ERROR);
}

GameCore::_GameStatus GameCore::WanJian(int player)
{
    QString strMsg = _T("%1使用%2")
        .arg(getPlayerShowName(player))
        .arg(_Pai::getName(_Pai::Value_WanJian));
    emit s_Message(strMsg);
    ShowChuPaiMessage(strMsg, m_nGameMessageDelay);

    if(WenTi(player, strMsg, 0) == false)
    {
        //m_strMsg = _T("%1回答错误!锦囊牌失效!")
        //    .arg(getPlayerShowName(player));
        //emit s_Message(m_strMsg);
        //ShowChuPaiMessage(m_strMsg);
        return gameStatus();
    }
    if(gameStatus() != Game_Status_Continue)return gameStatus();
    //m_strMsg = _T("%1回答正确!")
    //    .arg(getPlayerShowName(player));
    //emit s_Message(m_strMsg);
    //ShowChuPaiMessage(m_strMsg);


    _GameButtonValue ret;
    int i = GetNextPlayer(player);
    for(; i != player; i = GetNextPlayer(i))
    {
        ret = ChuShan(i, 1, strMsg);
        if(ret == Game_Button_Cancel)
        {
            if(DiaoXue(1,i,player,_Pai::Value_WanJian) != Game_Status_Continue)return gameStatus();
        }
        else if(ret == Game_Button_OK)
        {
            ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);
            continue;
        }
        else
            return setGameStatus(Game_Status_ERROR);
    }
    return gameStatus();
}

GameCore::_GameStatus GameCore::NanMan(int player)
{
    QString strMsg = _T("%1使用%2")
        .arg(getPlayerShowName(player))
        .arg(_Pai::getName(_Pai::Value_NanMan));
    emit s_Message(strMsg);
    ShowChuPaiMessage(strMsg, m_nGameMessageDelay);

    if(WenTi(player, strMsg, 0) == false)
    {
        //m_strMsg = _T("%1回答错误!锦囊牌失效!")
        //    .arg(getPlayerShowName(player));
        //emit s_Message(m_strMsg);
        //ShowChuPaiMessage(m_strMsg);
        return gameStatus();
    }
    if(gameStatus() != Game_Status_Continue)return gameStatus();
    //m_strMsg = _T("%1回答正确!")
    //    .arg(getPlayerShowName(player));
    //emit s_Message(m_strMsg);
    //ShowChuPaiMessage(m_strMsg);


    _GameButtonValue ret;
    int i = GetNextPlayer(player);
    for(; i != player; i = GetNextPlayer(i))
    {
        ret = ChuSha(i,1,1,-1,strMsg);
        if(ret == Game_Button_Cancel)
        {
            if(DiaoXue(1,i,player,_Pai::Value_NanMan) != Game_Status_Continue)return gameStatus();
        }
        else if(ret == Game_Button_OK)
        {
            ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

            continue;
        }
        else
            return setGameStatus(Game_Status_ERROR);
    }
    return gameStatus();
}

bool GameCore::GaoKao(int player, int player1)
{
    m_strMsg = m_hashGameMessage[_Pai::Value_GaoKao][1]
        .arg(getPlayerShowName(player))
        .arg(getPlayerShowName(player1))
        .arg(_Pai::getName(_Pai::Value_GaoKao));
    emit s_Message(m_strMsg);
    ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

    bool bRet = WenTi(player1, m_strMsg, 0);
    if(bRet == false)
    {
        //m_strMsg = _T("%1回答错误!")
        //    .arg(getPlayerShowName(player1));
        //emit s_Message(m_strMsg);
        //if(gameStatus() != Game_Status_Continue)return gameStatus();
        if(gameStatus() != Game_Status_Continue)return false;
        DiaoXue(1,player1,player,_Pai::Value_GaoKao);
    }
    else
    {
        //m_strMsg = _T("%1回答正确!")
        //    .arg(getPlayerShowName(player1));
        //emit s_Message(m_strMsg);
        //ShowChuPaiMessage(m_strMsg);
        //return gameStatus();
    }
    return bRet;
}

int GameCore::ShanDian(int player, _Pai* p)
{
    //XiaoGuoQiPai();
    int ret = m_arrayPlayer[player].getPanDingPai(p);
    if(ret <= 0)
    {
        return ret;
    }
    emit s_RefreshAllPokePosition();

    m_strMsg = _T("%1装上%2")
        .arg(getPlayerShowName(player))
        .arg(_Pai::getName(_Pai::Value_ShanDian));
    emit s_Message(m_strMsg);
    //ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

    //Sleep(m_ComputerDelay);

    return ret;
}

int GameCore::Le(int player, int player1, _Pai* p)
{
    int ret = m_arrayPlayer[player1].getPanDingPai(p);
    if(ret <= 0)
    {
        return ret;
    }
    //XiaoGuoQiPai();

    emit s_RefreshAllPokePosition();

    m_strMsg = m_hashGameMessage[_Pai::Value_LeBuSiShu][1]
        .arg(getPlayerShowName(player))
        .arg(getPlayerShowName(player1))
        .arg(_Pai::getName(_Pai::Value_LeBuSiShu));
    emit s_Message(m_strMsg);
    //ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

    //Sleep(m_ComputerDelay);

    return ret;
}





















GameCore::_GameButtonValue GameCore::ChuShan(int player, int count, QString msg)
{
    if(m_arrayPlayer[player].isMe())
    {
        m_strMsg = msg +
                _T("，请出%1张%2")
                .arg(count)
                .arg(_Pai::getName(_Pai::Value_Shan));
    }

    _GameButtonValue ret;
    ret = ChuPai(player, GameCore::Game_ChuPai_Type_Pai, _Pai::Value_Shan, count, count, -1, 0, m_strMsg);

    if(ret == Game_Button_Cancel)
    {
        m_strMsg = _T("%1不出%2")
                .arg(getPlayerShowName(player))
                .arg(_Pai::getName(_Pai::Value_Shan));
        emit s_Message(m_strMsg);
        //ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);
    }
    else if(ret == Game_Button_OK)
    {
        XiaoGuoQiPai();

        switch(m_arrayStep[0].nSelectType[0])
        {
        case _BaseObject::Area_ShouPai:
            break;

        case _BaseObject::Area_JiNeng:
            switch(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].getJiNengPaiData(m_arrayStep[0].nSelectValue[0])->value())
            {
            case _Pai::Value_JiNeng_ShenQu:
                m_strMsg = _T("%1 技能发动")
                        .arg(_Pai::getName(_Pai::Value_JiNeng_ShenQu));
                if(WenTi(player, m_strMsg, 0) == false)
                {
                    ret = Game_Button_Cancel;
                }
                if(gameStatus() != Game_Status_Continue)
                    return Game_Button_ERROR;
                break;
            default:
                emit s_Critical(_T("[!GameCore]ChuShan JiNeng ERROR:%1!").arg(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].getJiNengPaiData(m_arrayStep[0].nSelectValue[0])->value()));
                setGameStatus(Game_Status_ERROR);
                return Game_Button_ERROR;
            }
            break;

        default:
            emit s_Critical(_T("[!GameCore]ChuShan ERROR:%1!").arg(m_arrayStep[0].nSelectType[0]));
            setGameStatus(Game_Status_ERROR);
            return Game_Button_ERROR;
        }
        m_strMsg = _T("%1出%2")
                .arg(getPlayerShowName(player))
                .arg(_Pai::getName(_Pai::Value_Shan));
        emit s_Message(m_strMsg);
    }
    else
    {
        emit s_Critical(_T("[!GameCore]ChuShan ERROR:%1!").arg(ret));
        setGameStatus(Game_Status_ERROR);
        return Game_Button_ERROR;
    }

    return ret;
}

GameCore::_GameButtonValue GameCore::ChuSha(int player, int min, int max, QVariant param, QString msg)
{
    if(m_arrayPlayer[player].isMe())
    {
        m_strMsg = msg +
                _T("，请出一张%1")
                .arg(_Pai::getName(_Pai::Value_Sha));
    }

    _GameButtonValue ret;
    ret = ChuPai(player,GameCore::Game_ChuPai_Type_Pai,_Pai::Value_Sha,min,max,param,0,m_strMsg);

    if(ret == Game_Button_Cancel)
    {
        m_strMsg = _T("%1不出%2")
                .arg(getPlayerShowName(player))
                .arg(_Pai::getName(_Pai::Value_Sha));
        emit s_Message(m_strMsg);
    }
    else if(ret == Game_Button_OK)
    {
        XiaoGuoQiPai(0);

        switch(m_arrayStep[0].nSelectType[0])
        {
        case _BaseObject::Area_ShouPai:
        case _BaseObject::Area_ZhuangBei:
            break;

        case _BaseObject::Area_JiNeng:
            switch(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].getJiNengPaiData(m_arrayStep[0].nSelectValue[0])->value())
            {
            case _Pai::Value_JiNeng_MengNaLiSha:
                m_strMsg = _T("%1 技能发动")
                        .arg(_Pai::getName(_Pai::Value_JiNeng_MengNaLiSha));
                if(WenTi(player, m_strMsg, 0) == false)
                {
                    ret = Game_Button_Cancel;
                }
                if(gameStatus() != Game_Status_Continue)
                    return Game_Button_ERROR;
                break;

            case _Pai::Value_JiNeng_ZuoYongLi:
                m_strMsg = _T("%1 技能发动")
                        .arg(_Pai::getName(_Pai::Value_JiNeng_ZuoYongLi));
                if(WenTi(player, m_strMsg, 0) == false)
                {
                    ret = Game_Button_Cancel;
                }
                if(gameStatus() != Game_Status_Continue)
                    return Game_Button_ERROR;
                break;

            default:
                emit s_Critical(_T("[!GameCore]ChuSha JiNeng ERROR:%1!").arg(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].getJiNengPaiData(m_arrayStep[0].nSelectValue[0])->value()));
                setGameStatus(Game_Status_ERROR);
                return Game_Button_ERROR;
            }
            break;

        default:
            emit s_Critical(_T("[!GameCore]ChuSha1 ERROR:%1!").arg(m_arrayStep[0].nSelectType[0]));
            setGameStatus(Game_Status_ERROR);
            return Game_Button_ERROR;
        }

        m_strMsg = _T("%1出%2")
                .arg(getPlayerShowName(player))
                .arg(_Pai::getName(_Pai::Value_Sha));
        emit s_Message(m_strMsg);

    }
    /*
    else if(ret == Game_Button_JiNeng)
    {
        switch(m_arrayStep[0].nSelectValue[0])
        {
        case _Pai::Value_JiNeng_ShenQu:
            m_strMsg = _T("%1 技能触发")
                    .arg(_JiNeng::getName(_JiNeng::JiNengValue_ShenQu));
            if(WenTi(player, m_strMsg, 0) == true)
            {
                ret = ChuPai(player,GameCore::Game_ChuPai_Type_JiNeng,_JiNeng::JiNengValue_ShenQu);
                XiaoGuoQiPai(0);

                m_strMsg = m_hashGameMessage[_Pai::Value_Sha][4]
                        .arg(getPlayerShowName(player))
                        .arg(_Pai::getName(_Pai::Value_Sha));
                emit s_Message(m_strMsg);
                ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

            }
            break;
        default:
            emit s_Critical(_T("[!GameCore]ChuSha JiNeng ERROR!"));
            setGameStatus(Game_Status_ERROR);
            return Game_Button_ERROR;
        }
    }*/
    else
    {
        emit s_Critical(_T("[!GameCore]ChuSha1 ERROR:%1!").arg(ret));
        setGameStatus(Game_Status_ERROR);
        return Game_Button_ERROR;
    }

    return ret;
}







GameCore::_GameStatus GameCore::XiaoGuoQiPai(int type)
{
    QVariantList playerTargetList;
    switch(m_arrayStep[0].nSelectType[0])
    {
    case _BaseObject::Area_ShouPai:
        switch(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].getShouPaiData(m_arrayStep[0].nSelectValue[0])->value())
        {
        case _Pai::Value_Sha:
            if(type == 1)
            {
                playerTargetList.append(m_arrayStep[0].nSelectPlayerID);
                playerTargetList.append(m_arrayStep[1].nSelectPlayerID);
            }
            emit s_ChuPaiOver(playerTargetList);
            QiPai(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].qiShouPai(m_arrayStep[0].nSelectValue[0],true));
            break;
        case _Pai::Value_Shan:
            for(int i = 0; i < m_arrayStep[0].nSelectCount; i++)
                QiPai(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].qiShouPai(m_arrayStep[0].nSelectValue[i],false));
            m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].tiaoZhengShouPaiDui();
            break;
        case _Pai::Value_Tao:
            QiPai(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].qiShouPai(m_arrayStep[0].nSelectValue[0],true));
            break;
        case _Pai::Value_Chai:
            if(type == 1)
            {
                playerTargetList.append(m_arrayStep[0].nSelectPlayerID);
                playerTargetList.append(m_arrayStep[1].nSelectPlayerID);
            }
            emit s_ChuPaiOver(playerTargetList);
            QiPai(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].qiShouPai(m_arrayStep[0].nSelectValue[0],true));
            break;
        case _Pai::Value_Shun:
            if(type == 1)
            {
                playerTargetList.append(m_arrayStep[0].nSelectPlayerID);
                playerTargetList.append(m_arrayStep[1].nSelectPlayerID);
            }
            emit s_ChuPaiOver(playerTargetList);
            QiPai(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].qiShouPai(m_arrayStep[0].nSelectValue[0],true));
            break;
        case _Pai::Value_WuZhong:
            QiPai(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].qiShouPai(m_arrayStep[0].nSelectValue[0],true));
            break;
        case _Pai::Value_JieDao:
            if(type == 1)
            {
                playerTargetList.append(m_arrayStep[0].nSelectPlayerID);
                playerTargetList.append(m_arrayStep[1].nSelectPlayerID);
                playerTargetList.append(m_arrayStep[1].nSelectPlayerID);
                playerTargetList.append(m_arrayStep[2].nSelectPlayerID);
            }
            emit s_ChuPaiOver(playerTargetList);
            QiPai(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].qiShouPai(m_arrayStep[0].nSelectValue[0],true));
            break;
        case _Pai::Value_WanJian:
            if(type == 1)
            {
                playerTargetList.append(m_arrayStep[0].nSelectPlayerID);
                playerTargetList.append(-1);
            }
            emit s_ChuPaiOver(playerTargetList);
            QiPai(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].qiShouPai(m_arrayStep[0].nSelectValue[0],true));
            break;

        case _Pai::Value_NanMan:
            if(type == 1)
            {
                playerTargetList.append(m_arrayStep[0].nSelectPlayerID);
                playerTargetList.append(-1);
            }
            emit s_ChuPaiOver(playerTargetList);
            QiPai(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].qiShouPai(m_arrayStep[0].nSelectValue[0],true));
            break;
        case _Pai::Value_GaoKao:
            if(type == 1)
            {
                playerTargetList.append(m_arrayStep[0].nSelectPlayerID);
                playerTargetList.append(m_arrayStep[1].nSelectPlayerID);
            }
            emit s_ChuPaiOver(playerTargetList);
            QiPai(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].qiShouPai(m_arrayStep[0].nSelectValue[0],true));
            break;

        case _Pai::Value_ShanDian:
            break;

        case _Pai::Value_LeBuSiShu:
            //playerTargetList.append(step[0].nSelectPlayerID);
            //playerTargetList.append(step[1].nSelectPlayerID);
            //emit s_ChuPaiOver(playerTargetList);
            break;
        default:
            emit s_Critical(_T("[!GameCore]XiaoGuoQiPai ERROR!"));
            return setGameStatus(Game_Status_ERROR);
        }
        break;

    case _BaseObject::Area_ZhuangBei:
        switch(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].getZhuangBeiData((_BaseObject::_Area)m_arrayStep[0].nSelectValue[0])->value())
        {
        case _Pai::Value_ZhangBa:
        case _Pai::Value_TanSu:
            QiPai(m_arrayPlayer[m_arrayStep[1].nSelectPlayerID].qiShouPai(m_arrayStep[1].nSelectValue[0],false));
            QiPai(m_arrayPlayer[m_arrayStep[1].nSelectPlayerID].qiShouPai(m_arrayStep[1].nSelectValue[1],false));
            m_arrayPlayer[m_arrayStep[1].nSelectPlayerID].tiaoZhengShouPaiDui();
            break;
        default:
            break;
        }
        break;

    case _BaseObject::Area_JiNeng:
        switch(m_arrayPlayer[m_arrayStep[0].nSelectPlayerID].getJiNengPaiData(m_arrayStep[0].nSelectValue[0])->value())
        {
        case _Pai::Value_JiNeng_ShenQu:
            QiPai(m_arrayPlayer[m_arrayStep[1].nSelectPlayerID].qiShouPai(m_arrayStep[1].nSelectValue[0],true));
            break;
        case _Pai::Value_JiNeng_MengNaLiSha:
            QiPai(m_arrayPlayer[m_arrayStep[1].nSelectPlayerID].qiShouPai(m_arrayStep[1].nSelectValue[0],true));
            break;
        case _Pai::Value_JiNeng_ZhanZhengZhiShen:
            QiPai(m_arrayPlayer[m_arrayStep[1].nSelectPlayerID].qiShouPai(m_arrayStep[1].nSelectValue[0],true));
            break;
        case _Pai::Value_JiNeng_KaiSa:
            QiPai(m_arrayPlayer[m_arrayStep[1].nSelectPlayerID].qiShouPai(m_arrayStep[1].nSelectValue[0],true));
            break;
        case _Pai::Value_JiNeng_ZuoYongLi:
            QiPai(m_arrayPlayer[m_arrayStep[1].nSelectPlayerID].qiShouPai(m_arrayStep[1].nSelectValue[0],true));
            break;
        case _Pai::Value_JiNeng_AYuWang:
        case _Pai::Value_JiNeng_DaHangHaiShiDai:
        case _Pai::Value_JiNeng_DuXiu:
        case _Pai::Value_JiNeng_JunShiTanDing:
        case _Pai::Value_JiNeng_MengGuDiGuo:
            break;
        default:
            break;
        }
        break;

    default:
        emit s_Critical(_T("[!GameCore]XiaoGuoQiPai ERROR 2!"));
        return setGameStatus(Game_Status_ERROR);
    }


    emit s_RefreshAllPokePosition();

    return gameStatus();
}


GameCore::_GameStatus GameCore::ZhuangBeiWuQi(int player)
{
    _Pai *p = m_arrayPlayer[player].qiShouPai(m_arrayStep[0].nSelectValue[0],true);

    m_strMsg = m_hashGameMessage[_Pai::Value_All][6]
            .arg(getPlayerShowName(player))
            .arg(p->getName());
    emit s_Message(m_strMsg);
    //ShowChuPaiMessage(m_strMsg, m_nGameMessageDelay);

    p = m_arrayPlayer[player].getZhuangBei(p);

    if(p != nullptr)
        QiPai(p);

    emit s_RefreshAllPokePosition();

    return gameStatus();
}
